package com.itheima;

/**
 * 2025/3/29 10:46
 */
public class ArrayDemo {

    public static void main(String[] args) {

        //数组的静态初始化--》定义的同时直接把数组的值给赋值
        int[] arr1 = {1, 2, 3, 4, 5,6,7,8,9,10};//简洁写法
        int[] arr2 = new int[]{1, 2, 3, 4, 5};//完整写法
        int arr3[] = {2, 4, 6, 8, 10};
        //数组的访问
        System.out.println(arr1);

        System.out.println(arr1[0]);
        System.out.println(arr1[1]);
        System.out.println(arr1[2]);
        arr1[3] = 100;

        System.out.println(arr1[3]);//100
        System.out.println("数组的长度：" + arr1.length);//5

        //遍历数组，使用for循环

        for(int i =0;i<arr1.length;i++){
            System.out.println(arr1[i]);
        }
        //创建了一个长度为5的动态数组
        int[] arr4 = new int[5];
        arr4[0] = 1;
        arr4[1] = 2;
        arr4[2] = 3;
        arr4[3] = 4;
        arr4[4] = 5;
        //遍历数组
        for(int i =0;i<arr4.length;i++){
            System.out.println(arr4[i]);
        }

    }

}
